﻿<%@ Application Language="C#" %>

<script runat="server">

    void Application_Start(object sender, EventArgs e)
    {
        // 在应用程序启动时运行的代码
        var file = this.Context.Server.MapPath("./license.lrc");
        Rsd.Dudu.ServicesContainer.Regist("2efe4b43c724440aab542abcb7f3b5aa",file);
        
        Rsd.Dudu.Web.WebApplication.Initial(this,() =>
        {
            //Rsd.Dudu.DBServices.MsSqlServerService ms = new Rsd.Dudu.DBServices.MsSqlServerService("192.168.152.142", "yz-wxjj", "sa", "123456");
            //ms.DBVersion = Rsd.Dudu.DBServices.MsSqlServerService.Version.V2008;

            //
            string host = System.Web.Configuration.WebConfigurationManager.AppSettings["host"];
            string port = System.Web.Configuration.WebConfigurationManager.AppSettings["port"];
            string dbName = System.Web.Configuration.WebConfigurationManager.AppSettings["dbName"];
            string user = System.Web.Configuration.WebConfigurationManager.AppSettings["user"];
            string password = System.Web.Configuration.WebConfigurationManager.AppSettings["password"];

            //
            Rsd.Dudu.DBServices.MySqlService ms = new Rsd.Dudu.DBServices.MySqlService(host, port, dbName, user, password);
            //
            host = System.Web.Configuration.WebConfigurationManager.AppSettings["hostLog"];
            port = System.Web.Configuration.WebConfigurationManager.AppSettings["portLog"];
            dbName = System.Web.Configuration.WebConfigurationManager.AppSettings["dbNameLog"];
            user = System.Web.Configuration.WebConfigurationManager.AppSettings["userLog"];
            password = System.Web.Configuration.WebConfigurationManager.AppSettings["passwordLog"];
            //
            Rsd.Dudu.DBServices.MySqlService msLog = new Rsd.Dudu.DBServices.MySqlService(host, port, dbName, user, password);
            //
            Rsd.Dudu.ServicesContainer.AddService(new Rsd.Faith.Core.DataStorage(ms,"",false),  new Rsd.Dudu.Web.ExceptionHandleService(),new Rsd.Dudu.Permission.PermSerivce());

            Rsd.Dudu.ServicesContainer.AddService(new Rsd.Dudu.Log.DbLogService(new Rsd.Faith.Core.DataStorage(msLog,"rsd_sys_"), Rsd.Dudu.Log.LogLevelTypes.DbSql|Rsd.Dudu.Log.LogLevelTypes.Error| Rsd.Dudu.Log.LogLevelTypes.Warn| Rsd.Dudu.Log.LogLevelTypes.Info),new Rsd.Dudu.Web.Log.UILogDbService(new Rsd.Faith.Core.DataStorage(msLog,"rsd_ui_")));
            Rsd.Dudu.ServicesContainer.AddService(new Rsd.Faith.Sys.Services.UserService());
            //Rsd.Dudu.ServicesContainer.GetService<Rsd.Dudu.Log.ILogService>(null).Debug("添加服务UserService");

            //加载组件

            Rsd.Dudu.Web.WebApplication.LoadPlugins(
                  Rsd.Faith.Using.Config.GetConfig("/")
                , Rsd.Faith.Bank.Config.GetConfig("/")
                , Rsd.Faith.Fiscal.Config.GetConfig("/")
                , Rsd.Faith.Info.Config.GetConfig("/")
                , Rsd.Faith.Report.Config.GetConfig("/")
                , Rsd.Faith.Sys.Config.GetConfig("/")
                , Rsd.Faith.Web.Config.GetConfig("/") );

            Rsd.Dudu.Web.WebApplication.RegistController<Rsd.Faith.Web.Controllers.DevController>("dev");
            Rsd.Dudu.Web.WebApplication.RegistController<Rsd.Dudu.Web.Controllers.LogController>("log");

        },"Faith");

        //
        var timer = new System.Timers.Timer(1000*60);
        timer.AutoReset = true;
        timer.Enabled = true;
        timer.Elapsed += new System.Timers.ElapsedEventHandler(TimerElapsed );
        timer.Start();
    }
    void TimerElapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
        var login = System.Web.Configuration.WebConfigurationManager.AppSettings["timerHost"] + "Verification/Login?userid=admin&pwd=654321";
        new Rsd.Faith.Web.Services.ApiTimerService().DoRequestApi(login);
    }
    void Application_End(object sender, EventArgs e)
    {
        //  在应用程序关闭时运行的代码
        //Rsd.Dudu.ServicesContainer.GetService<Rsd.Dudu.Log.ILogService>(null).Info("Application End");

    }
    void Request_Start(object sender, EventArgs e)
    {
        Rsd.Dudu.ServicesContainer.GetService<Rsd.Dudu.Log.ILogService>(null).Info("Request Start");
    }

    void Application_Error(object sender, EventArgs e)
    {
        // 在出现未处理的错误时运行的代码
        // Rsd.Dudu.ServicesContainer.GetService<Rsd.Dudu.Log.ILogService>(null).Info("Application Error");
    }

    void Session_Start(object sender, EventArgs e)
    {
        // 在新会话启动时运行的代码
        // Rsd.Dudu.ServicesContainer.GetService<Rsd.Dudu.Log.ILogService>(null).Info("Session Start");
    }

    void Session_End(object sender, EventArgs e)
    {
        // 在会话结束时运行的代码。 
        // 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为
        // InProc 时，才会引发 Session_End 事件。如果会话模式设置为 StateServer
        // 或 SQLServer，则不引发该事件。
        // Rsd.Dudu.ServicesContainer.GetService<Rsd.Dudu.Log.ILogService>(null).Info("Session End");
    }

</script>
